package com.example.kyyl.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.kyyl.R;
import com.example.kyyl.http.SPUtil;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class SetingActivity extends AppCompatActivity {

    private ImageView goback;
    private EditText ips;
    private Button bt_bc;
    private CheckBox cb_jzmm;
    SharedPreferences user;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seting);
        goback=findViewById(R.id.goback);
        ips=findViewById(R.id.ips);
        cb_jzmm=findViewById(R.id.cb_jzmm);
        bt_bc=findViewById(R.id.bt_bc);
        user = getSharedPreferences("TEXT", Context.MODE_PRIVATE);
        boolean isRemember = user.getBoolean("user", false);
        if (isRemember) {
            String name = user.getString("name1", "");
            String password1 = user.getString("password1", "");
            ips.setText(name);
            cb_jzmm.setChecked(true);
        }
        goback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        bt_bc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SPUtil.putString(SetingActivity.this,"ipaddress",ips.getText().toString());
                SharedPreferences.Editor editor = user.edit();
                if (cb_jzmm.isChecked()) {
                    System.out.println("11111111111ggggggggggggggggg");
                    editor.putBoolean("user", true);
                    editor.putString("name1", ips.getText().toString());
                } else {
                    editor.clear();
                }

                editor.commit();
                Toast.makeText(SetingActivity.this,"保存成功",Toast.LENGTH_LONG).show();
                finish();
            }
        });
    }
}
